﻿using System.Collections;
using System.Collections.Generic;
using System.IO;

namespace Nutilities.Net
{
    public abstract class BinaryWriterUtility
    {
        public delegate void WriteListElement<in T>(T element, BinaryWriter writer);

        public static void Write<T>(BinaryWriter writer, List<T> list, WriteListElement<T> writeListElement)
        {
            writer.Write(list.Count);
            foreach (var element in list)
            {
                writeListElement(element, writer);
            }
        }

        public static void Write(BinaryWriter writer, IList list)
        {
            writer.Write(list.Count);
            foreach (IBinaryWriteable element in list)
            {
                element.WriteTo(writer);
            }
        }
    }
}
